import 'package:easy_debounce/easy_debounce.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_my_app/provider/activity_provider.dart';
import 'package:flutter_my_app/provider/guangdiu_data.dart';
import 'package:flutter_my_app/provider/wallet_provider.dart';
import 'package:flutter_my_app/services/bip39help.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'models/guangdiu_item.dart';
import 'models/activity.dart';
import 'models/api_response.dart';

class WalletPage extends ConsumerWidget {
  const WalletPage({super.key});
  //已经有助记词方式 指定助记词
  final String mnemonic ='dynamic injury tower sentence chief fog fox parrot embody spot always chicken';
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final WalletState walletState = ref.watch(walletProvider);
    print("输出助记词 ${walletState.mnemonic}");
    print("输出私钥 ${walletState.privateKey}");
    return Container(
      width: double.infinity,
      alignment: Alignment.center,
      //decoration: BoxDecoration(color: Colors.red),
      child: Column(
        children: [
          Container(
            width: double.infinity,
            height: 60,
            alignment: Alignment.center,
            decoration: BoxDecoration(
               color: Colors.green
            ),
            child: Text(('@riverpod测试注解方式生成provider')),
          ),
          Container(
              height: 300,
              decoration: BoxDecoration(color: Colors.red),
              child: Column(
                children: [
                  Row(children: [
                    Text(
                      "助记词:",
                      style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                    ),
                    Flexible(child: Text(
                      walletState.mnemonic,
                      style: TextStyle(
                        fontSize: 16,
                      ),
                    ))
                  ]),
                  Row(children: [
                    Text(
                      "私钥:",
                      style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                    ),
                   Flexible(child:  Text(
                     walletState.privateKey,
                     style: TextStyle(
                       fontSize: 16,
                     ),
                   ))
                  ]),
                ],
              )),
          //dynamic injury tower sentence chief fog fox parrot embody spot always chicken
          GestureDetector(
              onTap: () {
                final Wallet wallet = ref.read(walletProvider.notifier);
                wallet.createWallet();
              },
              child: Container(
                width: double.infinity,
                height: 40,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Colors.yellowAccent,
                    borderRadius: BorderRadius.circular(10)
                ),
                child: (Text('创建钱包(每次创建钱包)')),
              )),
          GestureDetector(
              onTap: () {
                final Wallet wallet = ref.read(walletProvider.notifier);
                wallet.importWallet(mnemonic);
              },
              child: Container(
                width: double.infinity,
                height: 40,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Colors.yellowAccent,
                    borderRadius: BorderRadius.circular(10)
                ),
                child: (Text('导入助记词钱包 拿到私钥')),
              )),
        ],
      ),
    );
  }
}
